using System.Collections.Generic;
using System.Linq;
using NodeCanvas.Variables;
using UnityEngine;

namespace NodeCanvas.Actions
{
	[Category("GameObject")]
	public class GetAllChildGameObjects : ActionTask
	{
		[BlackboardOnly]
		public BBGameObjectList saveAs;

		public bool recursive;

		protected override void OnExecute()
		{
			List<Transform> list = new List<Transform>();
			foreach (Transform item in base.agent.transform)
			{
				list.Add(item);
				if (recursive)
				{
					list.AddRange(Get(item));
				}
			}
			saveAs.value = list.Select((Transform t) => t.gameObject).ToList();
			EndAction();
		}

		private List<Transform> Get(Transform parent)
		{
			List<Transform> list = new List<Transform>();
			foreach (Transform item in parent)
			{
				list.Add(item);
				list.AddRange(Get(item));
			}
			return list;
		}
	}
}
